package com.leyou.user.service;


import com.leyou.LyUserApplication;
import com.leyou.user.domain.UserManage;
import com.leyou.user.mapper.UserManageMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = LyUserApplication.class)
public class UserManageServiceTest {

    @Autowired
    private UserManageMapper userManageMapper;

    @Test
    public void queryUserManageByPage(){
        List<UserManage> userManages = userManageMapper.findAll();
        userManages.forEach(userManage -> {
            System.out.println(userManage);
        });
      }

      @Test
    public void queryUserManageById(){
          UserManage userManage = userManageMapper.selectByPrimaryKey(2);
          System.out.println(userManage);
      }


      @Test
    public void addUserManage(){
        UserManage userManage = new UserManage();
        userManage.setId(4l);
        userManage.setUsername("sss");
        userManage.setPassword("12312");
        userManageMapper.insertSelective(userManage);
        List roles = new ArrayList();
        roles.add(1);
        roles.add(2);
        roles.add(3);
        userManageMapper.insertUserRoles(userManage.getId(),roles);
      }

      @Test
    public void updateUserManage(){
        UserManage userManage = new UserManage();
          userManage.setId(4l);
          userManage.setUsername("bbbb");
          userManage.setPassword("321321");
          userManageMapper.updateByPrimaryKey(userManage);

          userManageMapper.deleteUserRole(userManage.getId());
      }
    }


